package ants.service;

import java.util.Set;

public class MainService {
	
	public static void main(String[] args) {
		BaiduSearchService baidu = new BaiduSearchService();
		BingSearchService bing = new BingSearchService();
		Set<String>  baiduSearchResult = null;
		Set<String>  bingSearchResult = null;
		
		String keyword = "蚂蚁";
		System.out.println("关键字为:"+keyword);
		
		System.out.println("-------------------------------------");
		System.out.println("开始百度搜索");
		//获取百度搜索引擎的结果
		baiduSearchResult = baidu.getSearchResult(keyword);	
		int baiduTotal = baiduSearchResult.size();
		if(baiduSearchResult!=null && baiduSearchResult.size()>0) {			
			System.out.println("百度第一页一共有:" + baiduTotal + "条域名不一样的");
			for(String url:baiduSearchResult) {
				System.out.println("url="+url);
			}
			System.out.println("搜索结束");
		} else {
			System.out.println("搜索失败");
		}
		
		System.out.println("-------------------------------------");
		System.out.println("开始必应搜索");
		//获取必应搜索引擎的结果
		bingSearchResult = bing.getSearchResult(keyword);
		int bingTotal = bingSearchResult.size();
		if(bingSearchResult!=null && bingSearchResult.size()>0) {			
			System.out.println("必应第一页一共有:" + bingTotal + "条域名不一样的");	
			for(String url:bingSearchResult) {
				System.out.println("url="+url);
			}
			System.out.println("搜索结束");
		} else {
			System.out.println("搜索失败");		
		}
		System.out.println("-------------------------------------");
		System.out.println("-------------开始比较----------------");
		
		if(baiduSearchResult.size() <= bingSearchResult.size()) {
			int baiduNum = 0;
			for(String baiduUrl:baiduSearchResult) {				
				if(bingSearchResult.contains(baiduUrl)) {
					baiduNum++;
					System.out.println(baiduUrl+" 为两边都有的搜索结果");
				}
						
			}
			System.out.println("搜索结果的域名重复率为:" + baiduNum*100.0f/bingTotal + "%");
		} else {
			int bingNum = 0;
			for(String baiduUrl:baiduSearchResult) {				
				if(bingSearchResult.contains(baiduUrl)) {
					bingNum++;
					System.out.println(baiduUrl+" 为两边都有的搜索结果");
				}
			}
			System.out.println("搜索结果的域名重复率为:" + bingNum*100.0f/baiduTotal + "%");
		}
		
		
	}
}
